import { fileURLToPath, URL } from "node:url";
// @ts-ignore
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import ReactivityTransform from "@vue-macros/reactivity-transform/vite";

export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
  const env = loadEnv(mode, process.cwd());
  console.log(env);
  return {
    plugins: [vue(), vueJsx(), ReactivityTransform()],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    // 全局设置样式
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@import "@/assets/css/tarot.scss";',
        },
      },
    },
    server: {
      cors: true,
      host: "0.0.0.0",
      port: Number(env.VITE_APP_PORT),
      proxy: {
        [env.VITE_APP_SERVICE_FIX]: {
          target: env.VITE_APP_SERVICE_API,
          changeOrigin: true,
          rewrite: (path) =>
            path.replace(new RegExp("^" + env.VITE_APP_SERVICE_FIX), ""),
        },
      },
    },
  };
});
